const express = require("express");
const route = express.Router();

//引入权限校验中间件
const isLoginMiddle = require("../middleware/isLoginMiddle")

//引入数据库
const advModel = require("../db/model/advModel")

//主要是为了书写一个接口,使用我们封装好的权限验证中间件
route.get("/getUpdateAdv", isLoginMiddle, async (req, res) => {
    //获取id
    const {
        _id
    } = req.query
    // console.log(_id);//62bf481299def971edce6a4e

    try {
        //在数据库中查询对应的数据
        const findResult = await advModel.findOne({
            _id
        })

        //把查询到的值响应给前端
        res.send({
            code: 10000,
            msg: "更新数据前查询当前数据成功",
            data: findResult
        })

    } catch (e) {
        res.send({
            code: 10001,
            msg: "更新数据前查询当前数据失败",
            data: null
        })
    }

})

module.exports = route;